import request from '@/utils/request'

// 作业信息模糊查询
// /assignments/getAssignmentList

// getAssignmentListAPI('123'); // 只传入 assignmentId
// getAssignmentListAPI('123', '456'); // 传入 assignmentId 和 courseId
// getAssignmentListAPI('123', '456', '789'); // 传入所有三个参数

export function getAssignmentListAPI(assignmentId, courseId, teacherId) {
    let queryString = '';
    if (assignmentId) {
        queryString += `assignmentId=${assignmentId}&`;
    }
    if (courseId) {
        queryString += `courseId=${courseId}&`;
    }
    if (teacherId) {
        queryString += `teacherId=${teacherId}&`;
    }
    queryString = queryString.slice(0, -1); // 去除最后一个 '&' 符号
    return request({
        url: '/assignments/getAssignmentList' + (queryString ? '?' + queryString : ''),
        method: 'GET',
    });
}
// 添加作业
// /assignments
export function addAssignmentAPI(data) {
    return request({
        url: '/assignments' ,
        method: 'POST',
        data
    });
}
// 修改作业
// /assignments/{assignmentId}
export function editAssignmentAPI(assignmentId,data) {
    return request({
        url: '/assignments/' + assignmentId ,
        method: 'PUT',
        data
    });
}


// 作业信息获取接口
// /assignments
export function queryAssignmentAPI(assignmentId) {
    return request({
        url: '/assignments' ,
        method: 'GET',
        params:{
            assignmentId: assignmentId
        }
    });
}

// 删除作业
// /assignments
export function deleteAssignmentAPI(assignmentId, courseId, teacherId) {
    let queryString = '';
    if (assignmentId) {
        queryString += `assignmentId=${assignmentId}&`;
    }
    if (courseId) {
        queryString += `courseId=${courseId}&`;
    }
    if (teacherId) {
        queryString += `teacherId=${teacherId}&`;
    }
    queryString = queryString.slice(0, -1); // 去除最后一个 '&' 符号
    return request({
        url: '/assignments' + (queryString ? '?' + queryString : ''),
        method: 'DELETE',
    });
}